home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 18 / CU Amiga Magazine's Super CD-ROM 18 (1997)(EMAP Images)(GB)[!][issue 1998-01].iso / CUCD / Utilities / PowerWindows / Developper / Examples / IconRenderer.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-01  |  4.9 KB  |  184 lines

  1. /*======== Example Source-Code for an external Icon-Renderer =========
  2.  
  3.    (C) Copyright 1997 by Georg Steger.
  4.    
  5.        Created with MaxonCPP 4.0 Pro
  6.  
  7.  
  8. Description:
  9. ¯¯¯¯¯¯¯¯¯¯¯¯
  10. This IconRenderer does a very simple Rendering. But it also shows
  11. you how to use the UserData in riInitIcon, riRenderIcon and
  12. riExitIcon. When you iconify a Window opened by the "Workbench"
  13. Task it will look a little bit different. Try it out!
  14.  
  15. ====================================================================*/
  16.  
  17.  
  18. /* OS-Includes */
  19.  
  20. #include <intuition/intuition.h>
  21. #include <graphics/gfx.h>
  22.  
  23. // #pragma header
  24.  
  25. /* Compiler-Includes */
  26.  
  27. #include <pragma/intuition_lib.h>
  28. #include <pragma/graphics_lib.h>
  29. #include <pragma/exec_lib.h>
  30. #include <string.h>
  31.  
  32. /* Program-Includes */
  33.  
  34. #include "/PWDevelopper.h"
  35.  
  36.  
  37. /* Vars */
  38.  
  39. struct GfxBase *GfxBase;
  40. struct IntuitionBase *IntuitionBase;
  41.  
  42. static struct Window *IconWin;
  43. static struct RastPort *rp;
  44. static struct Gadget *gad;
  45.  
  46. static struct TextExtent MyTE;
  47. static STRPTR title;
  48. static WORD   a,b,c,slen,x1,y1,x2,y2;
  49.  
  50. /* Program */
  51.  
  52. LONG RenderIcon(Msg msg)
  53. {
  54.     struct DrawInfo *di;
  55.  
  56.     switch (msg->MethodID)
  57.     {
  58.  
  59. /*==========  RI_INIT  ===========================================*/
  60.  
  61.         case RI_INIT:
  62.             GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",36);
  63.             IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",36);
  64.  
  65.             if ((!GfxBase) || (!IntuitionBase))
  66.             {
  67.                 if (GfxBase) CloseLibrary((struct Library *)GfxBase);
  68.                 if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
  69.                 return RIR_FAIL;
  70.             }
  71.             return RIR_OK;
  72.  
  73. /*==========  RI_EXIT  ===========================================*/
  74.  
  75.         case RI_EXIT:
  76.             if (GfxBase) CloseLibrary((struct Library *)GfxBase);
  77.             if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
  78.             return RIR_OK;
  79.  
  80. /*==========  RI_INITICON  =======================================*/
  81.  
  82.         case RI_INITICON:
  83.             if (RIINITICON_Msg->WinTask)
  84.             {
  85.                 if (strcmp(RIINITICON_Msg->WinTask->tc_Node.ln_Name,"Workbench")==0)
  86.                 {
  87.                     RIINITICON_Msg->UserData=(APTR)1;
  88.                 }
  89.             }
  90.             return RIR_OK;
  91.  
  92. /*==========  RI_EXITICON  =======================================*/
  93.  
  94.         case RI_EXITICON:
  95.             return TRUE;
  96.             
  97. /*==========  RI_RENDERICON  =====================================*/
  98.  
  99.         case RI_RENDERICON:
  100.             IconWin=RIRENDERICON_Msg->Icon;
  101.             rp=IconWin->RPort;
  102.             di=GetScreenDrawInfo(IconWin->WScreen);
  103.             if (!di) return RIR_FAIL;
  104.             SetAPen(rp,di->dri_Pens[SHADOWPEN]);
  105.             RectFill(rp,0,0,IconWin->Width-1,IconWin->Height-1);
  106.             SetAPen(rp,di->dri_Pens[SHINEPEN]);
  107.             RectFill(rp,1,1,IconWin->Width-2,IconWin->Height-2);
  108.             title=RIRENDERICON_Msg->ParentWin->Title;
  109.             if (title)
  110.             {
  111.                 a=rp->TxBaseline+(IconWin->Height - rp->TxHeight + 1) / 2;
  112.                 b=TextFit(rp,title,strlen(title),&MyTE,0,1,IconWin->Width-4,IconWin->Height);
  113.                 
  114.                 while (b && (title[b-1]==' ')) b--;
  115.     
  116.                 c=(IconWin->Width - TextLength(rp,title,b))/2;
  117.     
  118.                 SetAPen(rp,di->dri_Pens[SHADOWPEN]);
  119.                 SetDrMd(rp,JAM1);
  120.  
  121.                 Move(rp,c+1,a+1);
  122.                 Text(rp,title,b);                
  123.             }
  124.             
  125.             if (RIRENDERICON_Msg->UserData == (APTR) 1 )
  126.             {
  127.                 SetAPen(rp,di->dri_Pens[SHADOWPEN]);
  128.                 RectFill(rp,2,2,IconWin->Width-1-2,2);
  129.                 RectFill(rp,2,IconWin->Height-1-2,IconWin->Width-1-2,IconWin->Height-1-2);
  130.             }
  131.  
  132.             /* Let's check if there's any Close/Depth-Gadget */
  133.             
  134.             gad=IconWin->FirstGadget;
  135.             while (gad)
  136.             {
  137.                 x1=gad->LeftEdge;if (gad->Flags&GFLG_RELRIGHT) x1+=(IconWin->Width-1);
  138.                 y1=gad->TopEdge;if (gad->Flags&GFLG_RELBOTTOM) y1+=(IconWin->Height-1);
  139.                 x2=x1+gad->Width-1;if (gad->Flags&GFLG_RELWIDTH) x2+=(IconWin->Width);
  140.                 y2=y1+gad->Height-1;if (gad->Flags&GFLG_RELHEIGHT) y2+=(IconWin->Height);
  141.  
  142.                 if ((gad->GadgetType>YP_SYSTYPEMASK)==GTYP_CLOSE)    /* Close-Gadget found! */
  143.                 {
  144.                     SetAPen(rp,di->dri_Pens[SHADOWPEN]);
  145.                     RectFill(rp,x1,y1,x2,y2);
  146.                     SetAPen(rp,di->dri_Pens[SHINEPEN]);
  147.                     RectFill(rp,x1+1,y1+1,x2-1,y2-1);
  148.                     SetAPen(rp,di->dri_Pens[SHADOWPEN]);
  149.                     RectFill(rp,x1+5,y1+3,x2-5,y2-3);
  150.                 } else if ((gad->GadgetType>YP_SYSTYPEMASK)==GTYP_WDEPTH)    /* Depth-Gadget found! */
  151.                 {
  152.                     SetAPen(rp,di->dri_Pens[SHADOWPEN]);
  153.                     RectFill(rp,x1,y1,x2,y2);
  154.                     SetAPen(rp,di->dri_Pens[SHINEPEN]);
  155.                     RectFill(rp,x1+1,y1+1,x2-1,y2-1);
  156.                     SetAPen(rp,di->dri_Pens[SHADOWPEN]);
  157.                     RectFill(rp,x1+3,y1+3,x1+7,y1+6);
  158.                     RectFill(rp,x1+4,y1+4,x1+8,y1+7);
  159.                     SetAPen(rp,di->dri_Pens[SHINEPEN]);
  160.                     RectFill(rp,x1+5,y1+5,x1+7,y1+6);
  161.                 }
  162.                 gad=gad->NextGadget;
  163.             }
  164.             FreeScreenDrawInfo(IconWin->WScreen,di);
  165.             return RIR_OK;
  166.  
  167.         case RI_REFRESHIFRAME:
  168.             IconWin=RIREFRESHIFRAME_Msg->Icon;
  169.             di=GetScreenDrawInfo(IconWin->WScreen);
  170.             if (!di) return RIR_FAIL;
  171.             SetAPen(IconWin->RPort,di->dri_Pens[SHADOWPEN]);
  172.             Move(IconWin->RPort,0,0);
  173.             Draw(IconWin->RPort,IconWin->Width-1,0);
  174.             Draw(IconWin->RPort,IconWin->Width-1,IconWin->Height-1);
  175.             Draw(IconWin->RPort,0,IconWin->Height-1);    
  176.             Draw(IconWin->RPort,0,0);
  177.             FreeScreenDrawInfo(IconWin->WScreen,di);
  178.             return RIR_OK;
  179.             
  180.         default:
  181.             return RIR_FAIL;
  182.     }
  183. }
  184.